/**
 * 初始化部门详情对话框
 */
var addVisitedInfoDlg = {
    addVisitedInfoData: {},
    zTreeInstance: null,
    validateFields: {}
};

/**
 * 清除数据
 */
addVisitedInfoDlg.clearData = function () {
    this.addVisitedInfoData = {};
}

/**
 */
addVisitedInfoDlg.payment = function () {
    alert(111);
}

/**
 * 设置对话框中的数据
 *
 * @param key 数据的名称
 * @param val 数据的具体值
 */
addVisitedInfoDlg.set = function (key, val) {
    this.addVisitedInfoData[key] = (typeof value == "undefined") ? $("#" + key).val() : value;
    return this;
}

/**
 * 设置对话框中的数据
 *
 * @param key 数据的名称
 * @param val 数据的具体值
 */
addVisitedInfoDlg.get = function (key) {
    return $("#" + key).val();
}

/**
 * 关闭此对话框
 */
addVisitedInfoDlg.close = function () {
    var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
    parent.layer.close(index);
}


/**
 * 显示部门选择的树
 *
 * @returns
 */
addVisitedInfoDlg.showaddVisitedSelectTree = function () {
    var pName = $("#pName");
    var pNameOffset = $("#pName").offset();
    $("#parentaddVisitedMenu").css({
        left: pNameOffset.left + "px",
        top: pNameOffset.top + pName.outerHeight() + "px"
    }).slideDown("fast");

    $("body").bind("mousedown", onBodyDown);
}

/**
 * 隐藏部门选择的树
 */
addVisitedInfoDlg.hideaddVisitedSelectTree = function () {
    $("#parentaddVisitedMenu").fadeOut("fast");
    $("body").unbind("mousedown", onBodyDown);// mousedown当鼠标按下就可以触发，不用弹起
}

/**
 * 收集数据
 */
addVisitedInfoDlg.collectData = function () {
    this.set('id').set('customerName').set('economicAbility').set('pseudonym').set('customerPhone').set('customerSex').set('customerAge').set('ids')
        .set('birthday').set('customerStatus').set('referee').set('refereeShip').set('idCardNo').set('fixedTelephone')
        .set('qqNumber').set('wechatNumber').set('isHaveChildren').set('isReturnVisit').set('email').set('zipCode').set('identificationNumber')
        .set('numberOfAudits').set('finalAuditor').set('auditorTime').set('consumAbility').set('nonTransactionLevel').set('appointmentPayService')
        .set('transactionLevel').set('characters').set('consumptionHabits').set('otherContact').set('country').set('address')
        .set('province').set('cities').set('region').set('maritalStatus').set('occupation').set('filingTime').set('medicalRecordNumber')
        .set('arrivalTime').set('fieldTc').set('causeOfNoReturnVisit').set('entryClerk').set('recordPeople').set('reservationsId')
        .set('oneChannel').set('twoChannel').set('thrChannel').set('oneMedium').set('twoMedium').set('thrMedium')
        .set('archiving').set('toVoidremarks').set('remarks').set('actualAccountBalance').set('giveAccountBalance')
        .set('refundMoney').set('phoneSharShip').set('reservationsId').set('revisitContent').set('address');
}

/**
 * 验证数据是否为空
 */
addVisitedInfoDlg.validate = function () {
    $('#addVisitedInfoForm').data("bootstrapValidator").resetForm();
    $('#addVisitedInfoForm').bootstrapValidator('validate');
    return $("#addVisitedInfoForm").data('bootstrapValidator').isValid();
}

function onBodyDown(event) {
    if (!(event.target.id == "menuBtn" || event.target.id == "parentaddVisitedMenu" || $(
            event.target).parents("#parentaddVisitedMenu").length > 0)) {
        addVisitedInfoDlg.hideaddVisitedSelectTree();
    }
}


addVisitedInfoDlg.getEditd = function () {
    $(".modify").attr("readOnly", false);
    $(".modify").css("border", "1px solid #999999");
    $(".select_styles").removeAttr("disabled");
    $(".select_styles").css("border", "1px solid #999999");
    $("#remarks").attr("readOnly",false);
    if($("#oneChannel").val() == "直接上门"){
       $(".select_styles1").removeAttr("disabled");
       $(".select_styles1").css("border", "1px solid #999999");
    }
}


/**
 * 提交修改
 */
addVisitedInfoDlg.editSubmits = function () {
    this.clearData();
    this.collectData();
    if (!this.validate()) {
        return;
    }
    $(".modify").attr("readOnly", "true");
    $(".select_styles").attr("disabled", "disabled");
    $(".select_styles1").attr("disabled", "disabled");
    var isReturnVisit = $('#isReturnVisit').val();
    var causeOfNoReturnVisit = $('#causeOfNoReturnVisit').val();
    var refereeShip = $('#refereeShip').val();
    var referee = $('#referee').val();
    var select1 = $('#select1').val();
    this.addVisitedInfoData["customerSex"] = select1;
    if (refereeShip != "" && referee == "") {
        alert("请输入推荐人！");
        return
    }
    if (isReturnVisit == 2 && causeOfNoReturnVisit == "") {
        alert("请输入不回访原因！");
        return
    }
    //提交信息
    var ajax = new $ax(Feng.ctxPath + "/customer/update", function (data) {
        if (data == 1) {
            Feng.success("修改成功!");
            window.parent.Customer.table.refresh();
            addVisitedInfoDlg.close();
        } else {
            alert("客户电话已存在");
        }
    }, function (data) {
        Feng.error("修改失败!" + data.responseJSON.message + "!");
    });
    ajax.set(this.addVisitedInfoData);
    ajax.start();
}

/**
 * 提交添加
 */
addVisitedInfoDlg.addVisited = function () {
    this.clearData();
    this.collectData();
    if (!this.validate()) {
        return;
    }
    if ($('#revisitContent').val() == "" || $('#revisitContent').val() == null) {
        alert("请填写回访详情");
        return;
    }
    //提交信息
    var ajax = new $ax(Feng.ctxPath + "/consultant/addVisited", function (data) {
        Feng.success("操作成功!");
        window.parent.Consultant.table.refresh();
        addVisitedInfoDlg.close();
    }, function (data) {
        Feng.error("操作失败!" + data.responseJSON.message + "!");
    });
    ajax.set(this.addVisitedInfoData);
    ajax.start();
}

addVisitedInfoDlg.openBiles= function () {
    var customerId=document.getElementById("customerId").value;
    var index = layer.open({
        type: 2,
        title: '开单操作',
        area: ['100%', '100%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/consultant/isOperations/' + customerId
    });
    this.layerIndex = index;
    $('#cancels',document).click();
}

/**
 * 点击修改
 */
modifyAppointment = function(ids) {
    var index = layer.open({
        type: 2,
        title: '修改预约客户',
        area: ['60%', '90%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/doctorLooked/doctor_addTasks/' + ids
    });
    this.layerIndex = index;
};

/**
 * 提交添加
 */
addVisitedInfoDlg.addVisitedc = function () {
    this.clearData();
    this.collectData();
    if (!this.validate()) {
        return;
    }
    if ($('#revisitContent').val() == "" || $('#revisitContent').val() == null) {
        alert("请填写回访详情");
        return;
    }
//提交信息
    var ajax = new $ax(Feng.ctxPath + "/consultant/addVisited", function (data) {
        Feng.success("操作成功!");
        window.parent.Customer.table.refresh();
        addVisitedInfoDlg.close();
    }, function (data) {
        Feng.error("操作失败!" + data.responseJSON.message + "!");
    });
    ajax.set(this.addVisitedInfoData);
    ajax.start();
}

/**
 * 提交添加
 */
addVisitedInfoDlg.addVisitedd = function () {
    this.clearData();
    this.collectData();
    if (!this.validate()) {
        return;
    }
    if ($('#revisitContent').val() == "" || $('#revisitContent').val() == null) {
        alert("请填写回访详情");
        return;
    }
//提交信息
    var ajax = new $ax(Feng.ctxPath + "/reservations/addVisited", function (data) {
        Feng.success("操作成功!");
        window.parent.Reservations.table.refresh();
        addVisitedInfoDlg.close();
    }, function (data) {
        Feng.error("操作失败!" + data.responseJSON.message + "!");
    });
    ajax.set(this.addVisitedInfoData);
    ajax.start();
}

$(function () {
    Feng.initValidator("addVisitedInfoForm", addVisitedInfoDlg.validateFields);
});
